<template>
  <div>页面载入中......</div>
</template>

<script>
import { deepClone } from '@/utils'
import { ssoLoginApi } from '@/api/auth'
import { setToken } from '@/utils/auth'
import { useUserStore } from '@/store/modules/user'

export default {
  data() {
    return {
      token: this.$route.query.token || undefined
    }
  },
  created() {
    this.autoSsoLogin()
  },
  methods: {
    autoSsoLogin() {
      if (this.token) {
        ssoLoginApi(this.token)
          .then((res) => {
            setToken(res.data)
            const { getInfo } = useUserStore();
            getInfo()
            let data = deepClone(this.$route.query)
            delete data.target
            delete data.token
            this.$router.replace({ path: this.$route.query.target, query: data })
          })
          .catch((e) => {
            // 登录失败，提示错误
            this.msgError('登录授权失败：Token不合法')
          })
      } else {
        this.msgError('登录授权失败：Token不存在')
      }
    }
  }
}
</script>

<style lang="scss" scoped></style>
